//Thu Mar 25 18:45:50 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class NumberNeighbours
{
public:
	int numPairs(vector<int> numbers)
	{
		vector<string> v;
		for (int i = 0; i < (int) numbers.size(); i++)
		{
			stringstream ss;
			ss << numbers[i];
			string s = ss.str();
			sort(s.begin(), s.end());
			for (int j = 0; j < (int) s.size(); j++)
			{
				if (s[j] != '0')
				{
					s = s.substr(j);
					break;
				}
			}
			cout << s << endl;
			v.push_back(s);
		}
		sort(v.begin(), v.end());
		int count = 0;
		for (int i = 0; i < (int) v.size(); i++)
		{
			for (int j = i + 1; j < (int) v.size(); j++)
			{
				if (v[i] == v[j])
					count++;
			}
		}
		return count;
	}
};
/*
 * The basic idea about this is:
 * 1. Preprocess the data; translate the numbers into strings, then sort each string lexicographically.
 * 2. Remove the leading zeros.
 * 3. using O(n^2) to find out the same ones.
 * */
